package com.sgb.member.ui.adapter;

import android.content.Context;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.sgb.member.BR;
import com.sgb.member.R;
import com.sgb.member.databinding.ItemCollectiveJoinBinding;
import com.sgb.member.entity.CollectiveQuotationBean;
import com.swgk.core.recyclerview.adapter.BaseRecycleAdapter;
import com.swgk.core.recyclerview.adapter.ItemViewHolder;
import com.swgk.core.util.StringUtil;
import com.swgk.core.view.selection.CommonPopEntity;

public class CollectiveJoinAdapter extends BaseRecycleAdapter<CollectiveQuotationBean> {
    CommonPopEntity mEntity;

    public CollectiveJoinAdapter(Context context, CommonPopEntity entity) {
        super(context, R.layout.item_collective_join, null);
        mEntity = entity;
    }

    @Override
    public void convert(ItemViewHolder holder, CollectiveQuotationBean bean) {
        holder.setBinding(BR.itemBean, bean);
        ItemCollectiveJoinBinding binding = (ItemCollectiveJoinBinding) holder.getmBinding();
        binding.tvCollectiveMode.setVisibility(View.VISIBLE);
        if (!TextUtils.isEmpty(bean.getGroupBuyType())) {
            switch (bean.getGroupBuyType()) { // 汇集采购(2)或者 即报即采(1)
                case "1":
                    binding.tvCollectiveMode.setText("即报即采");
                    break;
                case "2":
                    binding.tvCollectiveMode.setText("汇集采购");
                    break;
                default:
                    binding.tvCollectiveMode.setText("");
                    break;
            }
        } else {
            binding.tvCollectiveMode.setVisibility(View.GONE);
        }
        if (!TextUtils.isEmpty(bean.getGroupbuyClass())) {
            switch (bean.getGroupbuyClass()) { // 商品材料、机械租赁、设备租赁）
                case "1":
                    binding.tvCollectiveType.setText("商品材料");
                    break;
                case "2":
                    binding.tvCollectiveType.setText("机械租赁");
                    break;
                case "3":
                    binding.tvCollectiveType.setText("设备租赁");
                    break;
                default:
                    binding.tvCollectiveType.setText("");
                    break;
            }
        } else {
            binding.tvCollectiveType.setVisibility(View.GONE);
        }

        binding.ivStatus.setVisibility(View.VISIBLE);
        updateImageStatus(binding.ivStatus, bean);
        updateGroupBuyType(binding.tvCollectiveMode, bean);
    }

    private void updateImageStatus(ImageView imageView, CollectiveQuotationBean entity) {
        // 集采状态（1 集采中 2 集采结束 4 集采失败 5 加盟中 6 报价中 ）
        switch (entity.getStatus()) {
            case 1:
                switch (entity.getPriceWarning()) {//价格预警 1 大于 2 等于 3 小于
                    case 1:
                        imageView.setImageResource(R.mipmap.member_icon_jcz_dy);
                        break;
                    case 2:
                        imageView.setImageResource(R.mipmap.member_icon_jcz_dengyu);
                        break;
                    case 3:
                        imageView.setImageResource(R.mipmap.member_icon_jcz_xy);
                        break;
                    default:
                        imageView.setImageResource(R.mipmap.member_icon_jcz_dengyu);
                        break;
                }
                break;
            case 2:
                imageView.setImageResource(R.mipmap.member_icon_jcwc);
                break;
            case 4:
                imageView.setImageResource(R.mipmap.member_icon_jcsb);
                break;
            case 5:
                imageView.setImageResource(R.mipmap.member_icon_jmz_qt);
                break;
            case 6:
                switch (entity.getPriceWarning()) {//价格预警 1 大于 2 等于 3 小于
                    case 1:
                        imageView.setImageResource(R.mipmap.member_icon_bjz_dy);
                        break;
                    case 2:
                        imageView.setImageResource(R.mipmap.member_icon_bjz_dengyu);
                        break;
                    case 3:
                        imageView.setImageResource(R.mipmap.member_icon_bjz_xy);
                        break;
                }
//                imageView.setImageResource(R.drawable.icon_bjz);
                break;
            default:
                imageView.setImageResource(R.mipmap.member_icon_jcz);
                break;
        }
    }


    private void updateGroupBuyType(TextView textView, CollectiveQuotationBean entity) {
        if(StringUtil.isEmpty(entity.getGroupBuyType())){
            textView.setVisibility(View.GONE);
        } else {
            textView.setVisibility(View.VISIBLE);
            switch (entity.getGroupBuyType()) {//集采类型: 1即报集采 2 汇总集采  3.企业专项
                case "1":
                    textView.setText(textView.getResources().getText(R.string.jbjc));
                    textView.setBackgroundResource(R.drawable.member_shape_gradient_blue);
                    break;
                case "2":
                    textView.setText(textView.getResources().getText(R.string.hzcg));
                    textView.setBackgroundResource(R.drawable.member_shape_gradient_yellow);
                    break;
                case "3":
                    switch (entity.getOfferType()) {//报价类型: 0：市场报价   1：会员报价
                        case "1":
                            textView.setBackgroundResource(R.drawable.member_icon_hybg);
                            textView.setText("客户报价");
                            break;
                        case "2":
                            textView.setBackgroundResource(R.drawable.member_shape_bule_green_button);
                            textView.setText("市场报价");
                            break;
                        case "3":
                            textView.setBackgroundResource(R.drawable.member_shape_bule_green_button);
                            textView.setText("成员报价");
                            break;
                    }
                    break;
                default:
                    textView.setVisibility(View.GONE);
                    break;
            }
        }

    }
}
